#include <iostream>
#include <cstdio>
#include <set>
#include <utility>

// #include <queue>
#include <ctime>
using namespace std;
#define MAX_M 10
typedef pair<int, int> PII;

int main() {
    int n;
    set<PII> s;
    scanf("%d", &n);
    for(int i = 0, a; i < n; i++) {
        cin >> a;
        s.insert(PII(a, i));
    }
    int ans = 0;
    for(int i = 1; i < n; i++) {
        int a = s.begin()->first;
        s.erase(s.begin());
        int b = s.begin()->first;
        s.erase(s.begin());
        ans += a + b;
        s.insert(PII(a + b, n + i));
    }
    cout << ans << endl;
    return 0;
}